<form id="learn-iter-form" lay-filter="learn-iter-form" class="layui-form model-form">
    <input name="userid" id="userid" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label">迭代内容</label>
        <div class="layui-input-block">
            <select name="sicode" id="sicode" lay-verify="required" required></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-block">
            <input name="statim" id="statim" type="text" autocomplete="off" class="layui-input" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input name="endtim" id="endtim" type="text" autocomplete="off" class="layui-input" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">理解程度</label>
        <div class="layui-input-block">
            <select name="unders" id="unders" lay-verify="required" required>
                <option value="A">完全理解</option>
                <option value="B">理解</option>
                <option value="C">不理解</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">练习程度</label>
        <div class="layui-input-block">
            <select name="practi" id="practi" lay-verify="required" required>
                <option value="A">熟练</option>
                <option value="B">能做</option>
                <option value="C">不会做</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="learn-iter-form-submit" lay-submit>保存</button>
    </div>
</form>
<script>
    layui.use(['layer', 'admin', 'form', 'layer','laydate'],function () {
        var admin = layui.admin;
        var form = layui.form;
        var config = layui.config;
        var layer = layui.layer;
        var laydate = layui.laydate;

        let value = admin.getTempData("t_learn_iter");
        // console.log(value)

        //获取迭代内容
        $.ajax({
            url: config.base_server + 'api-study/stageIter/getList',
            data:{
                access_token: config.getToken().access_token,
                sicode: value.stcode,
                userid: value.userid
            },
            type:'get',
            success: function (data){
                if (data.code === 0){
                    data = data.data;
                    // console.log(data)
                    for (var i=0;i<data.length;i++){
                        $("#sicode").append("<option value=\""+data[i].stitid+"\">"+data[i].conten+"</option>");
                    }
                    form.render('select');//刷新select选择渲染
                }else {
                    layer.msg('获取体系失败', {icon: 2, time: 1000});
                }
            }
        })
        //时间选择器
        laydate.render({
            elem:'#statim',
            min: value.statim
        });
        laydate.render({
            elem:'#endtim',
            min: value.statim
        });
        // 表单提交事件
        form.on('submit(learn-iter-form-submit)',function (data) {
            data.field.userid = value.userid;
            // console.log(data.field);
            admin.req('api-study/learnIter/insert', JSON.stringify(data.field), function (data) {
                if (data.code === 0) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }
            }, 'POST');
            return false;
        });
    });
</script>